package org.example.controller;


import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import java.util.Arrays;
import java.util.Date;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.example.entity.RepayPlan;
import org.example.entity.ThirdDeduct;
import org.example.service.IRepayPlanService;
import org.example.service.IThirdDeductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 还款计划表 前端控制器
 * </p>
 *
 * @author libo
 * @since 2023-11-20
 */
@RestController
@RequestMapping("/repay-plan")
public class RepayPlanController {

    @Autowired
    private IRepayPlanService repayPlanService;

    @Autowired
    private IThirdDeductService thirdDeductService;

    @RequestMapping("test")
    public Object testUpdate() {
        RepayPlan rp = new RepayPlan();
        rp.setOtherpayBatch("11");
        rp.setCertNo("11");
        rp.setId(1L);
        //        repayPlanService.updateById(rp);
        return repayPlanService.updateBatchById(Arrays.asList(rp));

        //        RepayPlan rp2 = new RepayPlan();
        //        rp2.setOtherpayBatch("11");
        //        rp2.setCertNo("11");
        //        rp2.setPeriod(1);
        //        rp2.setRepayday(new Date());
        //        rp2.setId(1L);
        //        repayPlanService.save(rp2);
    }

    @RequestMapping("trans")
    @ShardingTransactionType(TransactionType.XA)
    @DSTransactional
    public void testTrans() {
        RepayPlan rp2 = new RepayPlan();
        rp2.setOtherpayBatch("11");
        rp2.setCertNo("11");
        rp2.setPeriod(1);
        rp2.setRepayday(new Date());
        repayPlanService.saveTrans(rp2);

        ThirdDeduct thirdDeduct = new ThirdDeduct();
        thirdDeduct.setDeductMsg("trans");
        thirdDeductService.saveTrans(thirdDeduct);
    }
}

